class Solution {
public:
    int longestPalindrome(string s) {
        int n = s.size();
        unordered_map<char, int> hash;

        for (int i = 0; i < n; ++i)
        {
            ++hash[s[i]];
        }
        int flag = 0;
        int len = 0;
        for (int i = 0; i < 26; ++i)
        {
            if (hash['a' + i] % 2 != 0 || hash['A' + i] % 2 != 0)
                flag = 1;
            len += (hash['a' + i] / 2 * 2 + hash['A' + i] / 2 * 2);
        }
        return len + flag;
    }
};